package com.web.controller;

import com.bean.Users;
import com.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

// 作者
@Controller("usersController")
public class UsersController {
   //http://Localhost:8080/users
    //http://Localhost:8080/login

    @Autowired//自动注入
    @Qualifier("usersService") //注入：1.注入 2.反射
    private UsersService usersService;

    public UsersService getUsersService() {
        return usersService;
    }

    public void setUsersService(UsersService usersService) {
        this.usersService = usersService;
    }

    @RequestMapping(value = "/user/login" ,method = RequestMethod.POST)
    public String login(String nickname , String pwd , HttpSession session){

        Users user= usersService.login(nickname,pwd);

        if (user!=null){
            session.setAttribute("user",user);
            return "redirect:/index.jsp";
        }
        return "/login";
    }


}
